<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xhtml xsl">
	<xsl:output method="html" media-type="text/xhtml" omit-xml-declaration="yes" 
	version="1.0" encoding="UTF-8" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="yes"/>
	
	<xsl:template match="titleContent">
		<xsl:choose>
			<xsl:when test="@lang">
				<h1 xml:lang="{@lang}" lang="{@lang}"><xsl:value-of select="."/></h1>
			</xsl:when>
			<xsl:otherwise>
					<h1><xsl:value-of select="."/></h1>
			</xsl:otherwise>
		</xsl:choose>		
	</xsl:template>

	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
			<head>
				<!-- loading all the meta tags -->
				<xsl:for-each select="/page/headData/meta/*">
					<meta name="{name()}" content="{.}" />
				</xsl:for-each>
				<xsl:for-each select="/page/headData/meta">
					<xsl:if test="@content">
						<xsl:copy-of select="." />
					</xsl:if>
				</xsl:for-each>
				
				<meta name="author" content="LiberLab Group ©" />
				<!-- loading all the css sheets of the page -->
				<link rel="stylesheet" type="text/css" href="../../public_html/css/main.css" />
				<link type="text/css" rel="stylesheet" href="../../public_html/css/small.css" media="handheld, screen and (max-width:650px), only screen and (max-device-width:650px)" />
				<link type="text/css" rel="stylesheet" href="../../public_html/css/print.css" media="print" />
				<xsl:for-each select="/page/headData/css">
					<link rel="stylesheet" type="text/css" href="{.}" />				
				</xsl:for-each>
				<!-- USE <css>NEW CSS PATH</css> to add new CSS to th pages! -->

				<!-- loading all the javascript javascript -->
				<xsl:for-each select="/page/headData/javascript">
					<xsl:choose>
						<xsl:when test="@ie=1">
							<xsl:comment>__ieStart__</xsl:comment>
							<script type="text/javascript" src="{.}" />
							<xsl:comment>__ieEnd__</xsl:comment>
						</xsl:when>
						<xsl:otherwise>
							<script type="text/javascript" src="{.}" />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
				<!-- USE <javascript>NEW JAVASCRIPT PATH</javascript>to add new Javascript to the pages! -->	
				<!-- loading the rest, formatted as it is -->
				<xsl:for-each select="/page/headData/*[name() != 'css' and name() != 'javascript' and name() != 'meta' and name() != 'onload']">
					<xsl:copy-of select="." />
				</xsl:for-each>
			</head>
			<xsl:choose>
				<xsl:when test="/page/headData/onload">		
					<body onload="{/page/headData/onload/text()}">
						<xsl:call-template name="inside" />
					</body>		
				</xsl:when>
				<xsl:otherwise>
					<body>
						<xsl:call-template name="inside" />
					</body>		
				</xsl:otherwise>
			</xsl:choose>
		</html>
	</xsl:template>
	
	<xsl:template name="inside">
		<xsl:apply-templates select="/page/*[name() = 'infobar']"/>
		<div id="backgroundNav">
			<xsl:apply-templates select="/page/*[name() != 'headData' and name() != 'infobar']"/>
		</div> <xsl:comment>backgroundNav</xsl:comment>
	</xsl:template>	

</xsl:stylesheet>
